<?php
//定义路由
class Router
{
	public $module = null; //模块
	public $controller = null; //控制器
	public $action = null; //操作
	public $params = null; //参数
	

	private static $_instance = null;
	
	private function __construct()
	{
		$this->getPathInfo ();
	}
	
	private function __clone()
	{
	
	}
	
	static public function getInstance()
	{
		if (! self::$_instance instanceof self)
		{
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	
	private function getPathInfo()
	{
		$pathinfo = trim ( rtrim ( $_SERVER ['PATH_INFO'], C ( 'default_url_suffix' ) ), C ( 'url_separator' ) );
		$paths = explode ( C ( 'url_separator' ), $pathinfo );
		
		if (C ( 'is_group' ) == true)
		{
			$group_list = explode ( ',', C ( 'group_list' ) );
			foreach ( $group_list as $value )
			{
				$value = strtolower ( trim ( $value ) );
				if ($value == $paths [0])
				{
					$this->module = array_shift ( $paths );
				}
			}
			//如果模块为空则等于默认值
			if ($this->module == null)
			{
				$this->module = C ( 'default_group_name' );
			}
		}
		$controller = array_shift ( $paths );
		$this->controller = ($controller != null) ? $controller : C ( 'default_controller_name' );
		$action = array_shift ( $paths );
		$this->action = ($action != null) ? $action : C ( 'default_action_name' );
		$this->params = $paths;
	
	}
}